package com.yanchengtect.demo.progress.rollback.activity.dao;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.yanchengtect.demo.progress.dao.BaseDao;
import com.yanchengtect.demo.progress.dao.RowMapperUtil;
import com.yanchengtect.demo.progress.rollback.activity.domain.Activity;

/**
* @author 文心雕龙 Email：xuwenlong@shike8888.com
* @version 创建时间：2018年9月6日 下午6:19:56
* 类说明
*/
@Repository
public class ActivityDao extends BaseDao<Activity>{
	

	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Activity findById(int id) {
		String sql = "select act_id,left_num,product_name,unit_price,buy_sum from activity where act_id = ?";
		
		log.debug(sql);
		List<Activity> list = jdbcTemplate.query(sql, new Object[] {id},new RowMapperUtil(Activity.class));
		  
		  if (list.size()>0) {
			return list.get(0);
		 }else {
			 return null;
		 }
	}

	public int updateOne(Activity act) {
		HashMap<String,Object> conditions = new HashMap<String, Object>();
		conditions.put("act_id", act.getAct_id());
		act.setAct_id(null);
		return update("activity", act, conditions);
	}
}
